package org.sgx.gwteditors.client.impl1.basetypes;

import org.sgx.gwteditors.client.impl1.ui.colorpicker2.ColorUtil;

public class Color {
private static final String NONE = "none";
int red=0, green=0, blue=0, alpha=0;
/** a "none" or "transparent" color for indicating an object color property that can be null */ 
boolean none; 
/**
 * 
 * @param hex as returned by ColorPicker
 * @throws Exception 
 */
public Color(String hex) {
	setHex(hex);
}
public Color(int red, int green, int blue) {
	super();
	this.red = red;
	this.green = green;
	this.blue = blue;
}

public Color(int red, int green, int blue, int alpha) {
	super();
	this.red = red;
	this.green = green;
	this.blue = blue;
	this.alpha = alpha;
}

public int getRed() {
	return red;
}

public void setRed(int red) {
	this.red = red;
}

public int getGreen() {
	return green;
}

public void setGreen(int green) {
	this.green = green;
}

public boolean isNone() {
	return none;
}
public void setNone(boolean none) {
	this.none = none;
}
public int getBlue() {
	return blue;
}

public void setBlue(int blue) {
	this.blue = blue;
}

public int getAlpha() {
	return alpha;
}

public void setAlpha(int alpha) {
	this.alpha = alpha;
}
public String getHex()  {
	try {
		ColorUtil cu = new ColorUtil();
		cu.setRGB(red, green, blue);
		return cu.getHex();
	} catch (Exception e) {
	}
	return null;
}
@Override
public String toString() {
	return "rgb("+red+","+green+","+blue+")"; 
}
public void setHex(String hexColor) {
	if(hexColor==null||hexColor==NONE) {
		setNone(true);
		hexColor="ffffff";
	}
	else {
		setNone(false);
	}
	try {
		ColorUtil cu = new ColorUtil();
		cu.setHex(hexColor);
		red=cu.getRed();
		green=cu.getGreen();
		blue=cu.getBlue();
	} catch (Exception e) {
	}	
}

}
